package com.sino.tb.confirm.entiry;

import java.sql.*;
import java.util.*;
import xpubbean.Db.*;

public class DeclareDetail2 {
	private String[] title;
	private DeclareDetail[][] values;

	public String[] getTitle() {
		return title;
	}

	public void setTitle(String key, Connection conn) {
		String sql = "SELECT        max(count(1)) num " +
					 "FROM          t_pub_req2 req " +
					 "WHERE         req.c_seq_req = " + key + " " +
					 "GROUP BY      c_keyword ";
		int number = 0;
		ResultSetPlus rsp = new ResultSetPlus(sql, conn);
		if (rsp.next()) {
			number = Integer.parseInt(rsp.getFieldStr("num"));
		}

		sql =
				"SELECT        req.*, dd.c_item_status ,pj.c_type, dd.c_item_name " +
				"FROM          t_pub_req2 req,                            " +
				"              t_st_declare_detail dd,                    " +
				"              t_st_proj pj                               " +
				"WHERE         c_seq_req = " + key + " AND                " +
				"              req.c_prj_seq= dd.c_seq AND                " +
				"              pj.c_seq = dd.c_item_seq                   " +
				"ORDER BY      c_keyword, dd.c_seq                        ";

		try {
			rsp = new ResultSetPlus(sql, conn);
			String[] names = new String[number];
			String[] values = new String[rsp.getMaxRcdNo()];
			int i = 0;
			int j = 0;
			DeclareDetail[][] dds = new DeclareDetail[rsp.getMaxRcdNo()
									/ number][number];
			while (rsp.next() && j < number) {
				names[j++] = rsp.getFieldStr("c_item_name");
			}
			this.title = names;

			rsp.first();
			while (rsp.next()) {
				int x = i / number;
				int y = i % number;
				DeclareDetail value = new DeclareDetail();
				value.setKey(rsp.getFieldStr("c_seq"));
				value.setDeclareKey(rsp.getFieldStr("c_seq_req"));
				value.setDeclareItemKey(rsp.getFieldStr("c_prj_seq"));
				value.setItemKeyValue(rsp.getFieldStr("c_keyword"));
				value.setOldValue(rsp.getFieldStr("c_value_old"));
				value.setOldURL(rsp.getFieldStr("c_value_old_disp"));
				value.setNewValue(rsp.getFieldStr("c_value_new"));
				value.setNewURL(rsp.getFieldStr("c_value_new_disp"));
				value.setFinalValue(rsp.getFieldStr("c_value_final"));
				value.setReason(rsp.getFieldStr("c_reason"));
				value.setProcessKey(rsp.getFieldStr("c_rsp_seq"));
				value.setItemStatus(Integer.parseInt(rsp.getFieldStr(
						"c_item_status")));
				value.setItemType(Integer.parseInt(rsp.getFieldStr("c_type")));
				dds[x][y] = value;
				i++;
			}
            this.values = dds;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public DeclareDetail[][] getValues() {
		return values;
	}

	public void setValues(DeclareDetail[][] values) {
		this.values = values;
	}

}
